﻿// js files depended: none
// element config
var __expandImageSrc = "images/expand1.gif";
var __collapseImageSrc = "images/collapse1.gif";
var __mainframeId = "iframemain";
var __headExpandClassName = " up";
var __containerExpandClassName = " up";
var __selectedLIClassName = "selected";
var __siteName = "AMS商标业务系统 - ";

var _lastSelectedMenuItem = null;

function get(id) {
    return document.getElementById(id);
}

function Pid(id, tag) {
    if (!tag) {
        return document.getElementById(id);
    }
    else {
        return document.getElementById(id).getElementsByTagName(tag);
    }
}

function initializeMenus(containerId, headerElementTag, subContainerElementTag, eventName, expandedIndices) {
    this.headers = Pid(containerId, headerElementTag);
    this.containers = Pid(containerId, subContainerElementTag);

    function toggerExpandStyle(index) {
        var element = headers[index];
        var container = containers[index];
        var imgs = element.getElementsByTagName("img");
        var expandImg = null;
        if (imgs) {
            expandImg = imgs[0];
        }
        if (typeof element.expaneded == "undefined") {
            element.expaneded = false;
            element.tmpClass = element.className;
            container.tmpClass = container.className;
        }

        if (!element.expaneded) {
            element.expaneded = true;
            element.className = element.tmpClass + __headExpandClassName;
            container.className = container.tmpClass + __containerExpandClassName;
            if (expandImg) expandImg.src = __expandImageSrc;
        }
        else {
            element.expaneded = false;
            element.clasName = element.tmpClass;
            container.className = container.tmpClass;
            if (expandImg) expandImg.src = __collapseImageSrc;
        }
    }

    if (!eventName) eventName = "onclick";
    for (var i = 0; i < headers.length; i++) {
        headers[i].tmpIndex = i;
        headers[i][eventName] = function() {
            toggerExpandStyle(this.tmpIndex);
        }
    }

    if (typeof expandedIndices == "undefined") return;
    if (expandedIndices.length == 0) return;

    for (var i = 0; i < expandedIndices.length; i++) {
        if (expandedIndices[i] >= 0 && expandedIndices[i] < headers.length) {
            toggerExpandStyle(expandedIndices[i]);
        }
    }
}

function gotoPage(e, url) {
    if (_lastSelectedMenuItem) {
        _lastSelectedMenuItem.className = "";
    }
    e.className = __selectedLIClassName;
    _lastSelectedMenuItem = e;
    if (url && (url != "")) {
        get(__mainframeId).src = url;
        // TODO: not supported in ff
        document.title = __siteName + e.innerText;
    }
}

function gotoWorkPage(url) {
    if (url && (url != "")) {
        get(__mainframeId).src = url;
    }
}
//function toggerLeftVisible() {
//    var divMenu = get("drawer");
//    var divLeft = get("divLeft");
//    if (divMenu.style.display == "none") {
//        divMenu.style.display = "block";
//        divLeft.style.width = "100%";
//    }
//    else {
//        divMenu.style.display = "none";
//        divLeft.style.width = "10px";
//    }
//}

